package com.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pojo.Student;
import com.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * User: Qsxmj
 * Date: 2019/10/9 16:02
 * Content:
 *
 * @author qsxmji
 */
public interface UserDAO extends BaseMapper<User> {

    @Select("select user_password from user where user_name=#{user_name}")
    String chechPassword(@Param("user_name") String username);

    @Update("update user set user_password = #{user_password} where user_name = #{user_name}")
    int updatePasswordByName(@Param("user_name") String username,@Param("user_password") String newPassword);

    @Update("update user  set user_password = #{user_password}  where user_id = #{user_id}")
    int updatePasswordById(@Param("user_id") Integer id, @Param("user_password") String password);



    @Select("select user_id , user_password  from user where user_id=#{user_id} and user_password=#{user_password}")
    int checkPassword(@Param("user_id") Integer id,@Param("user_password") String oldpassword);

    public int addUser(User user);  //添加用户

    public int addstudent(Student student); //学生表添加用户名


    /**
     *
     * @param username 接收界面上的用户名
     * @return  查询数据库已存在的用户名
     */
    @Select("select user_name,role_id from user where user_name=#{user_name}")
    User findUser(@Param("user_name") String username);

    /**
     *
     * @param mail 接收界面上的邮箱
     * @return  查询数据库已存在的邮箱
     */
    @Select("select user_mail from user where user_mail=#{user_mail}")
    User findMail(@Param("user_mail") String mail);

    @Update("update user set role_id=#{roleId} where user_name=#{username}")
    int updateRole(String username, int roleId);
}
